home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: brianmcg@interaccess.com (Brian V. McGroarty)
- Newsgroups: comp.lang.c.moderated,comp.std.c
- Subject: Re: 'h' modifier in printf
- Date: 24 Mar 1996 11:49:12 -0600
- Organization: Internet Squire
- Sender: clc@solutions.solon.com
- Approved: clc@solutions.solon.com
- Message-ID: <4j41uo$nu7@solutions.solon.com>
- References: <4j06rd$82n@solutions.solon.com>
- Reply-To: brianmcg@interaccess.com
- NNTP-Posting-Host: solutions.solon.com
- X-Newsreader: Internet Squire 1.20
-
-
-
-
- Holden P wrote:
- >printf("Vanilla %X\nWith h %hX\n", -1, -1);
-
- >says
-
- >Vanilla FFFFFFFF
- >With h FFFF
-
-
- You are using a machine/compiler with a 32-bit integer size. "printf"
- follows the default integer size of the machine for its parameters when a
- size isn't explicitly given. A 16-bit integer machine/compiler would print
- "FFFF" for both.
-
-
-
- >In article <4i801c$455@solutions.solon.com>,
- > tada@athena.mit.edu (Michael J Zehr) writes:
-
- > >I was recently asked a question about printf whose answer I couldn't
- > >determine by reading K&R2 (and alas the company doesn't have a copy of
- > >the standard to refer to).
-
- > >The "h" modifier says the corresponding argument will be printed as a
- > >short or unsigned short.
-
- > >So, given:
-
- > >short s;
- > >printf("%d", s);
- > >printf("%hd", s);
-
- > >(Assuming of course that s has been initialized at some point.)
-
- > >Can these two ever be different? I'm aware of course that the short is
- > >widened to an int during the function call, but this preserves the
- > >value.
-
-
- All bits in the top half of a short which is extended to a full int will be
- set to the top bit of the original number. This assumes
- that the short isn't the same size as the default "int", which is of course
- a portability concern.
-
-
-
- ---
- Brian Valters McGroarty -- brianmcg@bix.com
- phone/fax (847) 439-7714
-